/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects.network;

import java.nio.ByteBuffer;

import org.latestbit.smartobjects.coders.IDataTypesCoder;
import org.latestbit.smartobjects.exceptions.*;
import org.latestbit.smartobjects.io.ResizableByteBuffer;

/**
 * Base interface for all connection based authentication 
 * procedure implementations (authenticators).
 * Authentication is the optional part of handshaking procedure.
 * All authenticators don't need to encrypt/decrypt credentials. 
 * There is the standard implementation for encrypting all required data for  the handshaking process (see IHandshakeManager)  
 * @author abdulla-a
 */
public interface IConnectionAuthenticator {
	
	/**
	 * Encodes credentials to byte stream 
	 * @param manager current handshake manager (the handshaking context)
	 * @param coder network protocol encoder
	 * @param writeBuffer output buffer
	 * @throws DataTypesCoderException
	 */
	public void encodeCredentials (			 
			IHandshakeManager manager,
			IDataTypesCoder coder,
			ResizableByteBuffer writeBuffer )
				throws DataTypesCoderException;
	
	/**
	 * Decodes and checks credentials from input byte stream
	 * @param manager current handshake manager (the handshaking context)
	 * @param coder network protocol decoder
	 * @param readBuffer input buffer
	 * @throws DataTypesCoderException
	 * @throws InvalidCredentialsException
	 */
	public void decodeCredentials (
			IHandshakeManager manager,
			IDataTypesCoder coder,
			ByteBuffer readBuffer ) 
				throws DataTypesCoderException, InvalidCredentialsException;
}
